We saw earlier that pandas is really good at dealing with dates. It is also amazing with strings! We're going to go back to our weather data from Chapter 5, here.

6.1 String operations

You'll see that the 'Weather' column has a text description of the weather that was going on each hour. We'll assume it's snowing if the text description contains "Snow".

pandas provides vectorized string functions, to make it easy to operate on columns containing text. There are some great examples in the documentation.

This gives us a binary vector, which is a bit hard to look at, so we'll plot it.

6.2 Use resampling to find the snowiest month

If we wanted the median temperature each month, we could use the resample() method like this:

Unsurprisingly, July and August are the warmest.

So we can think of snowiness as being a bunch of 1s and 0s instead of Trues and Falses:

and then use resample to find the percentage of time it was snowing each month

So now we know! In 2012, December was the snowiest month. Also, this graph suggests something that I feel -- it starts snowing pretty abruptly in November, and then tapers off slowly and takes a long time to stop, with the last snow usually being in April or May.

6.3 Plotting temperature and snowiness stats together

We can also combine these two statistics (temperature, and snowiness) into one dataframe and plot them together:

We'll use concat again to combine the two statistics into a single dataframe.

Uh, that didn't work so well because the scale was wrong. We can do better by plotting them on two separate graphs: